package com.ebupt.dbmodule

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.paging.DataSource
import androidx.paging.PagingData
import androidx.paging.PagingSource
import com.ebupt.service.AppUserInfo
import com.ebupt.service.User
import com.ebupt.service.UserDaoHelper

class DBRepo():IDBRepo {


    override fun addUser(context: Context) {
        val userList = mutableListOf<AppUserInfo>()
        for (i in 0..5){
            var appUserInfo = AppUserInfo()
            appUserInfo.userType = if (i%2==0) "普通用户" else "管理员"
            var user = User()
            user.userName = "小明"
            user.userAge = (10..30).random()
            user.id = i.toLong()
            appUserInfo.user = user

            userList.add(appUserInfo)
        }

        UserDaoHelper.addUserList(context,userList)

    }

    override fun deleteUser(context: Context,appUserInfo: AppUserInfo) = UserDaoHelper.deleteUser(context,appUserInfo)


    override fun updateUser(context: Context,appUserInfo: AppUserInfo) = UserDaoHelper.updateUser(context,appUserInfo)


    override fun queryUser(context: Context): LiveData<List<AppUserInfo>> = UserDaoHelper.queryUser(context)


    override fun queryUserNomal(context: Context): List<AppUserInfo> = UserDaoHelper.queryUserNomal(context)


    // override fun queryUserForPaging(context: Context): PagingData<AppUserInfo> = UserDaoHelper.queryUserForPaging(context)


}